﻿using LVYAN.Model;
using LVYAN.Model.AutoMation;
using LVYAN.Utils;
using System.Collections.Generic;
namespace LVYAN.Service.AIAPI
{
    /// <summary>
    /// 
    /// </summary>
    public class TaskManage : BaseAPI
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static List<RoomTask> GetTaskList(RobotModel Robot, RobotRobotOther RobotOther)
        {
            var Cache = new AIConfig().GetConfigModel(nameof(TaskManage), nameof(GetTaskList)).Cache;

            var content = JsonService.ToString(new
            {
                RobotName = Robot.RobotName,
                RobotCode = Robot.RobotCode,
                MacAddress = WinInfo.GetMacAddress(),
                MacIP = WinInfo.GetIP(),
                MacName = WinInfo.GetHostName(),
            });
            var Result = CacheManage<List<RoomTask>>.GetCache(content, () =>
            {
                new LoggerService().RequestMsgDebug("任务管理", "发送消息-任务管理", content);
                var result = new RequestService().PostJson($"{AIAPI}api/aichat/getRobotTaskList", content);
                var reponseData = JsonService.ToModel<ReponseData<List<RoomTask>>>(result);
                new LoggerService().ResponseMsgDebug("任务管理", "接受消息-任务管理", reponseData);
                return reponseData.Data;
            }, Cache);
            return Result;
        }

        /// <summary>
        /// 处理发生的任务
        /// </summary>
        /// <returns></returns>
        public static void SendTask(RobotModel Robot, RobotRobotOther RobotOther,   string TaskId)
        {
            var content = JsonService.ToString(new
            {
                RobotName = Robot.RobotName,
                RobotCode = Robot.RobotCode,
                TaskId = TaskId,
                MacAddress = WinInfo.GetMacAddress(),
                MacIP = WinInfo.GetIP(),
                MacName = WinInfo.GetHostName(),
            });
            new LoggerService().RequestMsgDebug("任务管理", "发送消息-发送", content);
            var result = new RequestService().PostJson($"{AIAPI}api/aichat/sendTask", content);
            new LoggerService().ResponseMsgDebug("任务管理", "接受消息-发送", result);
        }

    }
}
